﻿using System;
using System.IO;

namespace tester
{
    class Program
    {
        static void Main(string[] args)
        {
            var myProc = new System.Diagnostics.Process();
            myProc.StartInfo.FileName = args[0];
            myProc.StartInfo.Arguments = args[1] + " " + args[2];
            DateTime dt = DateTime.Now;
            myProc.Start();
            myProc.WaitForExit();
            DateTime dt1 = DateTime.Now;
            if (SortCorrectTest(args[1], args[2]))
            {
                TimeSpan period = dt1 - dt;
                Console.WriteLine("correct sort");
                Console.WriteLine("time spent {0}:{1}:{2}.{3}", period.Hours, period.Minutes, period.Seconds, period.Milliseconds);
                Console.ReadKey();
            }
            else
            {
                TimeSpan period = dt1 - dt;
                Console.WriteLine("incorrect sort");
                Console.WriteLine("time spent {0}:{1}:{2}.{3}", period.Hours, period.Minutes, period.Seconds, period.Milliseconds);
                Console.ReadKey();
            }
        }

        public static bool SortCorrectTest(string inFilePath, string outFilePath)
        {
            var inFI = new FileInfo(inFilePath);
            var outFI = new FileInfo(outFilePath);
            if (inFI.Length != outFI.Length)
                return false;
            StreamReader input = new StreamReader(outFilePath);
            uint counter = 0, prev = 0;
            while (!input.EndOfStream)
            {
                prev = counter;
                while (input.Peek() != ' ' && !input.EndOfStream)
                {
                    counter *= 10;
                    counter += (uint)(input.Read() - '0');
                }
                input.Read();
                if (counter < prev)
                    return false;
                counter = 0;
            }
            input.Close();
            return true;
        }
    }
}